const koa = require('koa')
// const sha1 = require('sha1')
const wechat = require('./wechat-lib/middleware')
const config = require('./config/config')
const reply = require('./wechat/reply')

const app = new koa()

// app.use(async (ctx, next)=>{
// 	console.log(ctx.query)
// 	const {
// 		signature,
// 		timestamp,
// 		nonce,
// 		echostr
// 	} = ctx.query
// 	const token = config.wechat.token
// 	let str = [token, timestamp, nonce].sort().join('')

// 	const sha = sha1(str)

// 	if(sha === signature){
// 		ctx.body = echostr
// 	}else{
// 		ctx.body = 'wrong'
// 	}
// })
app.use(wechat(config.wechat, reply.reply))

app.listen(config.port)
console.log('3306')